﻿using System;
using System.Web.Mvc;
using TestBat.ServiceLocator;

namespace TestBat.Frontend.Controllers.Factories
{
    public class ControllerFactory : DefaultControllerFactory
    {
        protected override IController GetControllerInstance(Type controllerType)
        {
            if (controllerType != null)
            {

                if (!typeof(IController).IsAssignableFrom(controllerType))
                    throw new ArgumentException(string.Format("Type requested is not a controller: {0}", controllerType.Name), "controllerType");

                var c = DefaultServiceLocator.Get(controllerType) as IController;

                return c;
            }
            else
                return base.GetControllerInstance(controllerType);
        }
    }
}
